package com.example.demo.dto;


import com.example.demo.entity.Task;

import java.time.LocalDateTime;

public class TaskDTO {
    private Long id;
    private String title;
    private String taskType;
    private String taskTypeText; // 枚举文本
    private String department;
    private String application;
    private String repository;
    private String currentApprovingDept;
    private String status;
    private String statusText; // pending -> 待处理
    private String createdBy;
    private String createdByRealName;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTaskType() {
        return taskType;
    }

    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }

    public String getTaskTypeText() {
        return taskTypeText;
    }

    public void setTaskTypeText(String taskTypeText) {
        this.taskTypeText = taskTypeText;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getApplication() {
        return application;
    }

    public void setApplication(String application) {
        this.application = application;
    }

    public String getRepository() {
        return repository;
    }

    public void setRepository(String repository) {
        this.repository = repository;
    }

    public String getCurrentApprovingDept() {
        return currentApprovingDept;
    }

    public void setCurrentApprovingDept(String currentApprovingDept) {
        this.currentApprovingDept = currentApprovingDept;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getStatusText() {
        return statusText;
    }

    public void setStatusText(String statusText) {
        this.statusText = statusText;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public String getCreatedByRealName() {
        return createdByRealName;
    }

    public void setCreatedByRealName(String createdByRealName) {
        this.createdByRealName = createdByRealName;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    // 静态方法：从 Entity 转 DTO
    public static TaskDTO fromEntity(Task task, String realName) {
        TaskDTO dto = new TaskDTO();
        dto.setId(task.getId());
        dto.setTitle(task.getTitle());
        dto.setTaskType(task.getTaskType());
        dto.setTaskTypeText(TaskTypeText.get(task.getTaskType()));
        dto.setDepartment(task.getDepartment());
        dto.setApplication(task.getApplication());
        dto.setRepository(task.getRepository());
        dto.setCurrentApprovingDept(task.getCurrentApprovingDept());
        dto.setStatus(task.getStatus());
        dto.setStatusText(StatusText.get(task.getStatus()));
        dto.setCreatedBy(task.getCreatedBy());
        dto.setCreatedByRealName(realName);
        dto.setCreateTime(task.getCreateTime());
        dto.setUpdateTime(task.getUpdateTime());
        return dto;
    }

    // 枚举文本映射
    private static class TaskTypeText {
        public static String get(String type) {
            switch (type) {
                case "code_release": return "代码发布";
                case "config_change": return "配置变更";
                case "data_fix": return "数据修正";
                case "emergency": return "紧急修复";
                default: return type;
            }
        }
    }

    private static class StatusText {
        public static String get(String status) {
            switch (status) {
                case "pending": return "待处理";
                case "completed": return "已完成";
                default: return status;
            }
        }
    }
}
